Skip to content

lsm6dsox: Add pedometer support#1091

Open
sebromero wants to merge 6 commits intomicropython:masterfrom
sebromero:pedometer
Open

lsm6dsox: Add pedometer support#1091
sebromero wants to merge 6 commits intomicropython:masterfrom
sebromero:pedometer

Conversation

@sebromero
Copy link

This pull request adds basic support for the LSM6DSOX IMU's built-in pedometer feature in the MicroPython driver, including new register definitions, helper methods, and a usage example. The main changes enable step counting, step detection interrupts, and configuration of debounce steps.

Signed-off-by: Sebastian Romero <s.romero@arduino.cc>
Signed-off-by: Sebastian Romero <s.romero@arduino.cc>
@sebromero sebromero force-pushed the pedometer branch 2 times, most recently from ae3b5ed to d5d8af9 Compare March 16, 2026 11:51
Signed-off-by: Sebastian Romero <s.romero@arduino.cc>
Signed-off-by: Sebastian Romero <s.romero@arduino.cc>
Signed-off-by: Sebastian Romero <s.romero@arduino.cc>
Copy link
Contributor

@iabdalkader iabdalkader left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Signed-off-by: Sebastian Romero <s.romero@arduino.cc>
Copy link
Member

@dpgeorge dpgeorge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a good addition, thanks!

Just a few comments which should help make the code a bit smaller.

_OUTX_L_XL = const(0x28)
_MLC_STATUS = const(0x38)
_STEP_COUNTER_L = const(0x62)
_EMB_FUNC_SRC = const(0x64)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two registers are in the embedded register set, so probably best to move their definition down below, after _EMB_FUNC_INT2.

_PAGE_RW = const(0x17)

_MD1_CFG = const(0x5E)
_MD2_CFG = const(0x5F)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two are part of the standard register set, so probably best moved up to just after _MLC_STATUS.

self._write_reg(reg, self._read_reg(reg) | mask)

def _clear_bits(self, reg, mask):
self._write_reg(reg, self._read_reg(reg) & ~mask)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest combining these two methods into a general _modify_bits(self, reg, clr, set) method. Then it could be more widely used (and also probably reduce code size); see below.


rw_bit = 0x20 if value is None else 0x40
# Clear both read and write bits first, then set read (bit 5) or write (bit 6).
self._write_reg(_PAGE_RW, (self._read_reg(_PAGE_RW) & 0x9F) | rw_bit)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be self._modify_bits(_PAGE_RW, 0x60, rw_bit).

if enable:
self._set_bits(_EMB_FUNC_EN_A, _PEDO_EN_MASK)
else:
self._clear_bits(_EMB_FUNC_EN_A, _PEDO_EN_MASK)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be self._modify_bits(_EMB_FUNC_EN_A, _PEDO_EN_MASK, enable and _PEDO_EN_MASK).

Same with int1_enable and int2_enable below.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants